package de.tum.in.eist.poll.client.controllers;

import com.google.gwt.user.client.rpc.AsyncCallback;

import de.tum.in.eist.poll.client.DelayedAction;
import de.tum.in.eist.poll.client.views.Views;
import de.tum.in.eist.poll.shared.beans.User;

/**
 * LoginController
 * @author Sebastian Hofstetter
 *
 */
public class LoginController extends Controller {
	
	/**
	 * performs the server login operation
	 * @param name username
	 * @param password userpassword
	 * @param callback
	 * @throws IllegalArgumentException
	 */
	public void login(String name, String password, AsyncCallback<User> callback) throws IllegalArgumentException {
		pollService.login(name, password, callback);
	}

	/**
	 * performs a logout and returns to the loginpage
	 */
	public void logout() {
		Controller.controller.setLoggedInUser(null, new DelayedAction() {

			@Override
			public void run() {
				Controller.controller.showPage(Views.login); // returns to the loginpage
			}
		});
	}
}
